﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using BLL;
using BLL.Managers;

namespace CorporateGymManagementSystem
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class LoginWindow : Window
    {
        public LoginWindow()
        {
            InitializeComponent();
            WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen;
        }

        private void forgotPasswordButton_Click(object sender, RoutedEventArgs e)
        {
            PasswordRecoveryWindow passwordRecoveryWindow = new PasswordRecoveryWindow();
            passwordRecoveryWindow.ShowDialog();
        }

        private void changePasswordButton_Click(object sender, RoutedEventArgs e)
        {
            PasswordChangeWindow passwordChangeScreen = new PasswordChangeWindow(userNameTextBox.Text);
            passwordChangeScreen.ShowDialog();
        }

        private void btnlogin_Click(object sender, RoutedEventArgs e)
        {
            lblLoginErrorMessage.Content = string.Empty;           
            string userName = userNameTextBox.Text;
            string password = passwordPasswordBox.Password;
            GymWorker worker = GymLoginManager.Instance.Login(userName, password);
            if (worker == null)
            {
                lblLoginErrorMessage.Content = "Username Or Password Incorrect!!!";
            }
            else
            {
                
                //GymWorkerManager.Instance.GetWorkers(true).ConvertAll((worker1) => worker1.Email).ToArray());
                worker.StartShift = DateTime.Now;
                this.Hide();
                MainApplicationWindow mainApplicationWindow = new MainApplicationWindow(worker);
                mainApplicationWindow.ShowDialog();
                worker.EndShift = DateTime.Now;
                GymWorkerManager.Instance.AddShift(worker);
                this.Close();
            }
        }
    }
}
